package com.leetcode.LC;

public class LC1009 {
    public int bitwiseComplement(int N) {

        String s = Integer.toBinaryString(N);
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                builder.append('1');
            } else {
                builder.append('0');
            }
        }
        String s1 = builder.reverse().toString();
        int sum = 0;
        for (int i = 0; i < s1.length(); i++) {
            sum += ((s1.charAt(i) - '0') * Math.pow(2, i));
        }
        return sum;

    }

    public static void main(String[] args) {
        System.out.println(new LC1009().bitwiseComplement(5));
    }
}
